<?php

namespace App\Models\finance;

use App\Models\AdminModel;
use App\Models\CustomerModel;
use App\Models\FlightModel;
use App\Models\TakeOrderModel;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model as BaseModel;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * 
 * @property int $id
 * @property int $take_order_id 提单ID
 * @property int $flight_id 航班ID
 * @property int $customer_id 客户ID
 * @property string $origin 起运地
 * @property string $destination 目的地
 * @property int $package_num 件数
 * @property float $gross_weight 毛重
 * @property float $volume_weight 体积重
 * @property float $charging_weight 计费重
 * @property float $air_freight_unit_price 空运单价
 * @property float $air_freight 空运费
 * @property float $bill_fee 提单费
 * @property float $delivery_fee 提货费
 * @property float $registration_fee 登记费
 * @property float $parking_fee 停车费
 * @property float $tunnel_fee 隧道费
 * @property float $customs_fee 报关费
 * @property float $hk_mainland_fee 中港费
 * @property float $customs_operation_fee 操作费
 * @property float $unloading_fee 卸货费
 * @property float $packing_fee 打包费
 * @property string $black_film 缠黑膜
 * @property string $pallet_black_film 打卡板缠黑膜
 * @property float $special_cargo_fee 特殊货物费
 * @property float $continued_fee 续页费
 * @property float $inspection_fee 报检录单服务费
 * @property float $electric_fee 验电费
 * @property float $storage_fee 仓租费
 * @property float $overnight_fee 压夜费
 * @property float $overtime_fee 加班费
 * @property float $cca_fee CCA费
 * @property float $scan_fee 扫描费
 * @property float $dispatch_fee 派送费
 * @property float $sorting_fee 分货费
 * @property float $loading_fee 打板费
 * @property float $special_goods_fee 特殊货物费
 * @property float $other_fee 其他费用
 * @property float $total_amount 总金额
 * @property int $status 状态
 * @property int $created_admin_id 创建人ID
 * @property string $created_at 创建时间
 * @property string $updated_at 更新时间
 * @property string $deleted_at 删除时间
 */
class ReceivableGenericModel extends BaseModel
{
    use HasFactory, SoftDeletes;

    protected $table = 't_receivable_generic';

    protected $primaryKey = 'id';

    public $timestamps = true;

    const CREATED_AT = 'created_at';
    
    const UPDATED_AT = 'updated_at';

    protected $guarded = [];

    protected $hidden = [
        'deleted_at',
    ];

    // 收款状态
    const STATUS_UNPAID = 1; // 未收款
    const STATUS_PARTIAL_PAID = 2; // 部分收款
    const STATUS_PAID = 3; // 已收款
    
    const STATUS_MAPS = [
        self::STATUS_UNPAID => '未收款',
        self::STATUS_PARTIAL_PAID => '部分收款',
        self::STATUS_PAID => '已收款',
    ];

    // 关联提单
    public function take_order(): BelongsTo
    {
        return $this->belongsTo(TakeOrderModel::class, 'take_order_id');
    }

    // 关联航班
    public function flight(): BelongsTo
    {
        return $this->belongsTo(FlightModel::class, 'flight_id');
    }

    // 关联客户
    public function customer(): BelongsTo
    {
        return $this->belongsTo(CustomerModel::class, 'customer_id');
    }

    // 创建人
    public function create_admin(): BelongsTo
    {
        return $this->belongsTo(AdminModel::class, 'created_admin_id');
    }

    //详情
    public function detail(): HasMany {
        return $this->HasMany(ReceivableGenericDetailModel::class, 'generic_id');
    }

    //大客户大包
    public function notify(): HasMany {
        return $this->hasMany(\App\Models\lazada\BigBagModel::class, 'take_order_id', 'take_order_id');
    }
} 